package Dao;

import Pojo.Journalism;
import Pojo.NewInfo;

import org.apache.ibatis.annotations.*;

import java.util.List;

public interface JournalismMapper {
    //    统计会员数
    @Select("SELECT COUNT(username) FROM user;")
    int usernum();

    //    统计新闻个数
    @Select("SELECT COUNT(title) FROM news;")
    int newnum();

    //    统计标签个数
    @Select("SELECT COUNT(DISTINCT type) FROM news;")
    int tagnum();

    //    查询新闻内容
    @Select("SELECT * FROM news ORDER BY time DESC LIMIT #{start},#{size};")
    List<NewInfo> info(@Param("start")int  start,@Param("size")int size);

    //    发布新闻
    @Insert("INSERT into news (title,simply,content,type) VALUES (#{title} ,#{simply} ,#{content} ,#{type});")
    int addnew(NewInfo newInfo);

//    根据id查找新闻
    @Select("SELECT * FROM news WHERE id = #{id};")
    NewInfo findidinfo(@Param("id") String  id);

//    根据id修改新闻
    @Update("UPDATE news set title=#{title},simply=#{simply},content=#{content},type =#{type} WHERE id = #{id}")
    int updatanew(NewInfo newInfo);
//    根据id 删除新闻
    @Delete("DELETE FROM news WHERE id = #{id};")
    int delectnew(@Param("id") String id);
}
